package com.macroye.controller;

import cn.hutool.json.JSON;
import com.alibaba.fastjson.JSONObject;
import com.macroye.entity.BrokerHomePage;
import com.macroye.entity.req.BrokerLoginVo;
import com.macroye.result.Result;
import com.macroye.service.BrokerService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/broker")
@Log4j2
public class BrokerController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    BrokerService brokerService;

    /**
     * 登录
     * @return
     */
    @PostMapping("/brokerLogin")
    public Result<BrokerLoginVo> brokerLogin(@RequestBody BrokerLoginVo broker){
        log.info("请求路径：【{}】，请求方式：【{}】，请求参数：【{}】",
                request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(broker));

        Result<BrokerLoginVo> result=brokerService.brokerLogin(broker);

        log.info("请求路径：【{}】，请求方式：【{}】，响应结果：【{}】",
                request.getRequestURI(),request.getMethod(), result);
        return result;
    }

    /**
     * 查找经纪人首页信息
     * @return
     */
    @PostMapping("/findHomePageInformation")
    public Result<BrokerHomePage> findHomePageInformation(){
        log.info("请求路径：【{}】，请求方式：【{}】",
                request.getRequestURI(),request.getMethod());
        //查找数据
        Result<BrokerHomePage> result =brokerService.findHomePageInfotmation();

        log.info("请求路径：【{}】，请求方式：【{}】，响应结果：【{}】",
                request.getRequestURI(),request.getMethod(), result);
        return result;
    }


}
